﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import Modules.stats.experiments.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class HUDDailyDripComponent extends HUDComponent implements IPlayerStateObserver {

        private var m_icon:DisplayObject = null;
        private var m_iconHolder:AssetPane;
        private var m_locked:Boolean = false;
        private var m_hidden:Boolean = false;
        private var m_created:Boolean = false;

        public function HUDDailyDripComponent(){
            Global.player.addObserver(this);
            this.reset();
        }
        override public function reset():void{
            var _local3:String;
            if (this.m_hidden){
                return;
            };
            alpha = 0;
            this.m_locked = false;
            var _local1:int;
            if (Global.player.dailyRewards){
                for (_local3 in Global.player.dailyRewards) {
                    _local1++;
                };
            };
            if (_local1 > 0){
                this.m_locked = true;
            };
            if (Global.player.level < 7){
                this.m_locked = true;
            };
            var _local2 = (ExperimentDefinitions.DAILY_EMAIL == Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_DAILY_DRIP_EMAIL));
            if (!_local2){
                this.m_locked = true;
            };
            if (((!(this.m_locked)) && (!(this.m_created)))){
                this.create();
                this.m_created = true;
            };
        }
        override public function isVisible():Boolean{
            return (((this.m_created) && (!(this.m_locked))));
        }
        protected function hide():void{
            removeEventListener(MouseEvent.CLICK, this.onMouseClick, false);
            Z_TweenLite.to(this, 2, {
                alpha:0,
                onComplete:this.doHide
            });
            this.m_locked = true;
            this.m_hidden = true;
        }
        protected function doHide():void{
            if (m_jWindow){
                m_jWindow.visible = false;
                m_jWindow.buttonMode = false;
            };
            this.m_locked = true;
            this.m_hidden = true;
        }
        private function create():void{
            m_jWindow = new JWindow(this);
            m_jPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, true);
            _local1.align = TextFormatAlign.RIGHT;
            this.addEventListener(MouseEvent.CLICK, this.onMouseClick, false, 0, true);
            m_jPanel.append(ASwingHelper.verticalStrut(15));
            LoadingManager.load(Global.getAssetURL("assets/hud/icon_emailReward.png"), this.onIconLoaded);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local2.append(ASwingHelper.horizontalStrut(0));
            m_jWindow.setContentPane(m_jPanel);
            ASwingHelper.prepare(m_jWindow);
            m_jWindow.cacheAsBitmap = true;
            m_jWindow.show();
            this.alpha = 0;
            this.visible = false;
            if (!this.m_locked){
                this.visible = true;
                this.addTooltip();
            };
        }
        private function onIconLoaded(_arg1:Event):void{
            var _local2:Loader = (_arg1.target.loader as Loader);
            this.m_icon = _local2.content;
            addChildAt(this.m_icon, 0);
            m_jPanel.setPreferredSize(new IntDimension(this.m_icon.width, this.m_icon.height));
            m_jPanel.setMinimumSize(new IntDimension(this.m_icon.width, this.m_icon.height));
            m_jPanel.setMaximumSize(new IntDimension(this.m_icon.width, this.m_icon.height));
            ASwingHelper.prepare(m_jWindow);
            m_jWindow.useHandCursor = true;
            m_jWindow.buttonMode = true;
            alpha = 0;
            Z_TweenLite.to(this, 2, {alpha:1});
        }
        private function onMouseClick(_arg1:Event):void{
            var _local2:DailyDripDialog;
            if (!this.m_locked){
                StatsManager.sample(100, StatsCounterType.DAILY_BONUS, "email", "email_hud_clicked");
                _local2 = new DailyDripDialog();
                UI.displayPopup(_local2, true, "DailyDripDialog", true);
                this.hide();
            };
        }
        private function addTooltip():void{
            m_toolTip = new ToolTip(function ():String{
                return (ZLoc.t("Dialogs", "DripHUD_tooltip"));
            });
            m_toolTip.attachToolTip(m_jPanel);
            m_toolTip.hideCursor = true;
        }
        public function levelChanged(_arg1:int):void{
            var _local2 = (ExperimentDefinitions.DAILY_EMAIL == Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_DAILY_DRIP_EMAIL));
            if (!_local2){
                return;
            };
            if (!_local2){
                this.m_locked = true;
            };
            if (_arg1 == 7){
                this.m_locked = false;
                if (this.m_created == false){
                    this.create();
                    this.m_created = true;
                };
                this.visible = true;
                Z_TweenLite.to(this, 1, {alpha:1});
                this.addTooltip();
            };
        }
        public function xpChanged(_arg1:int):void{
        }
        public function commodityChanged(_arg1:int, _arg2:String):void{
        }
        public function energyChanged(_arg1:Number):void{
        }
        public function goldChanged(_arg1:int):void{
        }
        public function cashChanged(_arg1:int):void{
        }

    }
}//package Display.hud.components 
